package com.ad.pet.app.main.adapter;

import android.app.Activity;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.common.data.utils.SpUtil;
import com.ad.pet.common.data.utils.glide.GlideUtil;
import com.ad.pet.constant.Constant;
import com.ad.pet.models.remote.home.HomeMall;

import java.util.List;

/**O9P/iV1sRAbJ8j5pFrgjzKI6kyI=
 * 首页下方的推荐商品的adapter
 * Created by SEELE on 2018/4/8.
 */
public class HomeIndexMallAdapter extends BaseMultiItemQuickAdapter<HomeMall, BaseViewHolder> {

    public HomeIndexMallAdapter( @Nullable List<HomeMall> data) {
        super(data);
        addItemType(0,R.layout.item_home_product);
        addItemType(1,R.layout.item_good_search_list_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, final HomeMall item) {
        helper.setText(R.id.tv_title, item.getSales() + " " + mContext.getString(R.string.has_buy)).
                setText(R.id.tv_price, SpUtil.getInstance().getString(Constant.CURRENCY_LABEL,"US $") + item.getPrice());
        final ImageView view = helper.getView(R.id.iv_pic);


        GlideUtil.load(mContext, item.getImage(), view);

        TextView tvTitleName = helper.getView(R.id.tv_title_name);
        if (tvTitleName!=null){
            tvTitleName.setText(item.getName());
        }

        RelativeLayout relativeLayoutTips = helper.getView(R.id.relative_tips);
        TextView tvDikou = helper.getView(R.id.tv_dikou);
        if (relativeLayoutTips!=null){
            if (TextUtils.isEmpty(item.getAfter_discount_price_text())){
                relativeLayoutTips.setVisibility(View.GONE);
            }else {
                relativeLayoutTips.setVisibility(View.VISIBLE);
            }
        }
        if (tvDikou!=null){
            tvDikou.setText(item.getAfter_discount_price_text());
        }

        TextView tvOldPrice = helper.getView(R.id.tv_old_price);
        TextView tvCost = helper.getView(R.id.tv_cost);
        TextView tvBack = helper.getView(R.id.tv_back);


        if (tvOldPrice!=null){
            tvOldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            tvOldPrice.setText(SpUtil.getInstance().getString(Constant.CURRENCY_LABEL,"US $")+item.getOrig_price());
        }
        if (tvCost!=null){
            tvCost.setText("-"+item.getDiscount()+"%");
        }

        if (tvBack!=null){
            if (TextUtils.isEmpty(item.getReturn_red_price())){
                tvBack.setVisibility(View.GONE);
            }else {
                tvBack.setVisibility(View.VISIBLE);
            }
            tvBack.setText("全球包邮");
        }
        helper.getView(R.id.linear_out).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Navigation.goGoodDetail((Activity) mContext, MainActivity.REQUEST_GO_MALL,item.getProduct_id());
            }
        });


//        Logger.e("home_index_hash_code:"+view.hashCode());
    }


}
